********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
clear *
**# Bookmark (input)
use $inputdirectory/INB_extensive2019

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(excashas exlnassets dtop66e14 dmid6633e14)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

gen q1=(time>=tm(2019m3)&time<=tm(2019m5))
gen q2=(time>=tm(2019m6)&time<=tm(2019m8))
gen q3=(time>=tm(2019m9)&time<=tm(2019m11))
gen q4=(time>=tm(2019m12)&time<=tm(2020m2))
gen timeq=0
replace timeq=1 if q1==1
replace timeq=2 if q2==1
replace timeq=3 if q3==1
replace timeq=4 if q4==1

*ATTENTION MID
foreach x in  1 3 4  {
gen q`x'exlnassets=q`x'*exlnassets
gen q`x'excashas=q`x'*excashas
gen q`x'dtop66e14=q`x'*dtop66e14
gen q`x'dmid6633e14=q`x'*dmid6633e14
}

**# Bookmark (output - columns 1 and 2)
cd $outputdirectory
est clear
reghdfe t0123 q*dtop66e14 q*dmid6633e14 q*exlnassets q*excashas lncrefin, absorb(bankid borrowerid#time) vce(cluster bankid)
est save TABVIIB_C1234
reghdfe t0123 q*dtop66e14 q*dmid6633e14 q*exlnassets q*excashas lncrefin, absorb(bankid borrowerid#timeq) vce(cluster bankid)
est save TABVIIB_C1234,append
cd ..

********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
clear *
**# Bookmark (input)
use $inputdirectory//INB_extensive2015

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(excashas exlnassets dtop85e13)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

gen q1=(time>=tm(2014m7)&time<=tm(2014m9))
gen q2=(time>=tm(2014m10)&time<=tm(2014m12))
gen q3=(time>=tm(2015m1)&time<=tm(2015m3))
gen q4=(time>=tm(2015m4)&time<=tm(2015m6))
gen timeq=0
replace timeq=1 if q1==1
replace timeq=2 if q2==1
replace timeq=3 if q3==1
replace timeq=4 if q4==1

foreach x in 1 3 4  {
gen q`x'exlnassets=q`x'*exlnassets
gen q`x'excashas=q`x'*excashas
gen q`x'dtop85e13=q`x'*dtop85e13
}

**# Bookmark (output - columns 3 and 4)
cd $outputdirectory
reghdfe t0123 q*dtop85e13 q*exlnassets q*excashas lncrefin, absorb(bankid borrowerid#time) vce(cluster bankid)
est save TABVIIB_C1234,append
reghdfe t0123 q*dtop85e13 q*exlnassets q*excashas lncrefin, absorb(bankid borrowerid#timeq) vce(cluster bankid)
est save TABVIIB_C1234,append
cd ..

